package com.google.code.securityflow.util

import java.io.{FileWriter, File}

object Logger {

  val logfile = new File("target/output.txt");
  val writer = new FileWriter(logfile);
  var indent = 0;

  def clearIndent() {
    indent = 0;
  }

  def popIndent(level: Int = 2) {
    if (indent > 0) {
      indent = indent - level;
    }
  }

  def pushIndent(level: Int = 2) {
    indent = indent + level;
  }

  def writeHeadline(title: String) {
    clearIndent();
    writeln();
    writeln("*" * 80);
    writeln("*" * 5 + "" * 5 + title + "" * (80 - 3 * 5 - title.length) + "*" * 5);
    writeln("*" * 80);
    writeln();
  }

  def writeSubHeadline(title: String) {
    writeln("--- " + title + " ---");
  }

  def writeln() {
    writeln("");
  }

  def writeln(message: String) {
    val msg = "" * indent + message.replaceAll("n", "" * indent + "n") + "\n";

    Console.print(msg);
    writer.write(msg);
    writer.flush();
  }

}